package com.zkca.xf.presenter;

import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.zkca.xf.base.BasePresenter;
import com.zkca.xf.manager.DataManager;
import com.zkca.xf.model.javabean.test.LoginDto;
import com.zkca.xf.model.javabean.test.Result;
import com.zkca.xf.model.javabean.uploadbean.RequestInspect;
import com.zkca.xf.view.Test_Wu;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.observers.DefaultObserver;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by li on 2019/1/6.
 */

public class Login_WuPresenter extends BasePresenter {
    private DataManager dataManager;
    private Test_Wu taskLView;
    public Login_WuPresenter(LifecycleProvider<ActivityEvent> provider, Test_Wu taskLView) {
        super(provider);
        dataManager = DataManager.getInstance();
        this.taskLView=taskLView;
    }

    public void Login_wubL(LoginDto requestInspect) {
        dataManager.Login_wu(requestInspect)
                .subscribeOn(Schedulers.io())// 在子线程中进行Http访问
                .observeOn(AndroidSchedulers.mainThread())// UI线程处理返回接口
                .compose(getProvider().<Result>bindUntilEvent(ActivityEvent.DESTROY))// onDestroy取消订阅
                .subscribe(new DefaultObserver<Result>() {// 订阅
                    @Override
                    public void onNext(Result s) {
                        taskLView.login_wu(s);
                    }

                    @Override
                    public void onError(Throwable e) {
                        taskLView.showError(e.getMessage());
                    }

                    @Override
                    public void onComplete() {
                        taskLView.hideProgressDialog();
                    }
                });
    }

}
